window.addEventListener('load', function () {
    var reg = /^[\w]{6,16}$/ //密码表达式
    var reg2 = /[\s]*/;
    var regtel = /^1[3|4|5|7|8]\d{9}$/; //手机号表达式
    var tel = document.querySelector('#tel');
    var pwd = document.querySelector('#pwd');
    var pwd2 = document.querySelector('#pwd2');
    var inp = document.querySelector('.reg_form').querySelectorAll('input');

    //手机号判断
    tel.addEventListener('blur', function () {
        if (regtel.test(tel.value)) {
            this.nextElementSibling.className = 'success';
            this.nextElementSibling.innerHTML = ' <i class="succes_icon"></i>输入正确';
        } else {
            this.nextElementSibling.className = 'error';
            this.nextElementSibling.innerHTML = ' <i class="error_icon"></i>手机号码格式不正确，请重新输入';
        }
    })

    //密码判断
    pwd.addEventListener('blur', function () {
        if (reg.test(pwd.value)) {
            this.nextElementSibling.className = 'success';
            this.nextElementSibling.innerHTML = ' <i class="succes_icon"></i>输入正确';
        } else {
            this.nextElementSibling.className = 'error';
            this.nextElementSibling.innerHTML = ' <i class="error_icon"></i>密码为 6-16 位，请重新输入';
        }
    })

    //重复输入密码判断
    pwd2.addEventListener('blur', function () {
        if (pwd.value != pwd2.value) {
            this.nextElementSibling.className = 'error';
            this.nextElementSibling.innerHTML = ' <i class="error_icon"></i>密码不正确，请重新输入';
        } else {
            this.nextElementSibling.className = 'success';
            this.nextElementSibling.innerHTML = ' <i class="succes_icon"></i>输入正确';
        }
    })

    for(var i = 0; i < inp.length; i++){
        inp[i].addEventListener('blur',function(){
            inp[i].blur();
        })
    }
    

})